package com.ymatou.iapi.marketingmanage.testcase;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.ymatou.iapi.marketingmanage.parameter.CreateSellerPromotionBean;
import com.ymatou.iapi.marketingmanage.parameter.GetProductPromotionPolicyBean;
import com.ymatou.iapi.marketingmanage.parameter.GetPromotionByIdBean;
import com.ymatou.iapi.marketingmanage.parameter.Promotion;
import com.ymatou.iapi.marketingmanage.parameter.PromotionPolicy;
import com.ymatou.iapi.marketingmanage.parameter.PromotionValue;
import com.ymatou.iapi.marketingmanage.parameter.SellerPromotionListBean;
import com.ymatou.iapi.marketingmanage.service.GetProductPromotionPolicyCall;
import com.ymatou.iapi.marketingmanage.service.GetPromotionByIdCall;
import com.ymatou.iapi.marketingmanage.service.SellerPromotionListByStateCall;
import com.ymatou.iapi.marketingmanage.service.SellerPromotionListCall;
import com.ymatou.iapi.trading.operate.parameter.enums.PromotionTypeEnum;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JSellerPromotionCallService;
import com.ymttest.database.mongo.NewSellerPromotionInfoWapper;
import com.ymttest.database.mongo.YmtBuyerProductWapper;
import com.ymttest.utils.DiffUtil;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;

/**
 * 促销活动列表 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_DiffPromotion {
	

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("促销活动列表");
	}

	@Before
	public void caseUp() {
		
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult("diff");
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_DiffPromotion_001() {
		Logger.start(true, "GetPromotionById");
		try {
			 GetPromotionByIdBean getpromotionbyidBean;
			GetPromotionByIdCall getpromotionbyidCall;
			getpromotionbyidBean = new GetPromotionByIdBean();
			getpromotionbyidCall = new GetPromotionByIdCall();
			ArrayList<String[]> fl = TestDataManager.getData("0623.txt");
			
			for (String []s : fl) {
				//设置比较器
				DiffUtil diff = new DiffUtil();
				//设置输出文件
				String difffile="diff.txt";
				diff.setLogFile(difffile);
				//设置忽略列表
				List<String> list=new ArrayList<>();
				list.add("Msg");
				list.add("Data.PromotionInfo.PromotionLimitNum");
				list.add("Data.PromotionInfo.PromotionState");
				diff.setIgnoreList(list);
				
				//设置过滤器,对比时间的前19位
				Map<String, String> m=new HashMap<>();
				m.put("Data.PromotionInfo.PromotionBeginTime","^.{19}");
				m.put("Data.PromotionInfo.AddTime","^.{19}");
				m.put("Data.PromotionInfo.PromotionEndTime","^.{19}");
				
				diff.setPrecision(m);
				
				//设置对比字段是否去除首尾空白符
				diff.isTrim(true);
				
				//开始比较
				Integer sid=Integer.valueOf(s[1]);
				Integer pid=Integer.valueOf(s[0]);
				getpromotionbyidBean.setPromotionId(pid);
				getpromotionbyidBean.setSellerId(sid);
				getpromotionbyidCall.setData(getpromotionbyidBean);
				getpromotionbyidCall.callService();
				
				GetPromotionByIdCall getpromotionbyidCall2 = new GetPromotionByIdCall("marketingseller_api");
				getpromotionbyidCall2.setData(getpromotionbyidBean);
				getpromotionbyidCall2.callService();
				
				boolean identical=diff.compareJsonString(getpromotionbyidCall2.getReturnData(), getpromotionbyidCall.getReturnData());
				if(!identical){
					diff.appendLogFile( "sellerid:"+sid+":promotionid:"+pid);
				}
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_DiffPromotion_002() {
		Logger.start(true, "GetProductPromotionPolicy");
		try {
			GetProductPromotionPolicyBean getproductpromotionpolicyBean;
			GetProductPromotionPolicyCall getproductpromotionpolicyCall;
			getproductpromotionpolicyBean=new GetProductPromotionPolicyBean();
			getproductpromotionpolicyCall=new GetProductPromotionPolicyCall();
			ArrayList<String[]> fl = TestDataManager.getData("0623.txt");
			
			for (String []s : fl) {
				//设置比较器
				DiffUtil diff = new DiffUtil();
				//设置输出文件
				String difffile="diff4.txt";
				diff.setLogFile(difffile);
				//设置忽略列表
				List<String> list=new ArrayList<>();
				list.add("Msg");
//				list.add("Data.PromotionInfo.PromotionValues.AmountCondition");
				diff.setIgnoreList(list);
				
				//设置过滤器,对比时间的前19位
				Map<String, String> m=new HashMap<>();
				m.put("Data.PromotionInfo.PromotionBeginTime","^.{19}");
				m.put("Data.PromotionInfo.AddTime","^.{19}");
				m.put("Data.PromotionInfo.PromotionEndTime","^.{19}");
				
				diff.setPrecision(m);
				
				//设置对比字段是否去除首尾空白符
				diff.isTrim(true);
				
				//开始比较
				Integer sid=Integer.valueOf(s[1]);
				Integer pid=Integer.valueOf(s[0]);
				getproductpromotionpolicyBean.setProductId("");
				getproductpromotionpolicyBean.setSellerId(sid);
				getproductpromotionpolicyCall.setData(getproductpromotionpolicyBean);
				getproductpromotionpolicyCall.callService();
				
				GetProductPromotionPolicyCall getproductpromotionpolicyCall2 = new GetProductPromotionPolicyCall("marketingseller_api");
				getproductpromotionpolicyCall2.setData(getproductpromotionpolicyBean);
				getproductpromotionpolicyCall2.callService();
				
				boolean identical=diff.compareJsonString(getproductpromotionpolicyCall2.getReturnData(), getproductpromotionpolicyCall.getReturnData());
				if(!identical){
					diff.appendLogFile( "sellerid:"+sid+":promotionid:"+pid);
				}
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}